package com.exception.runtime.exception;

import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * 把“被检查异常Exception”转换为“不被检查的异常RuntimeException”
 * 
 * @author Administrator
 * 
 */
public class TurnOffChecking {

	public static void main(String[] args) {
		WrapCheckException wce = new WrapCheckException();
		// 无须捕获异常，因为已经转换为“不被检查的异常”
		wce.throwRuntimeException(3);
		// 或者也可以选择捕获
		for (int i = 0; i < 4; i++) {
			try {
				if (i < 3) {
					wce.throwRuntimeException(i);
				} else {
					throw new SomeOtherException();
				}
			} catch (SomeOtherException e) {
				System.out.println("SomeOtherException");
			} catch (RuntimeException re) {
				try {
					throw re.getCause();
				} catch (FileNotFoundException e) {
					System.out.println("FileNotFoundException");
				} catch (IOException e) {
					System.out.println("IOException");
				} catch (Throwable e) {
					System.out.println("Throwable");
				}
			}
		}
	}

}
